const Ajv = require("ajv")

const ajv = new Ajv()

/**
 * 
 * @param {Object} schema JSON schema 规则
 * @param {Object} data 待校验的数据
 */
function validate(schema, data={}) {
    const validate = ajv.compile(schema)
    const valid = validate(data)
    if (!valid) {
        return validate.errors[0]
    }
}

module.exports = validate